<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\SystemGroupXCourse
 *
 * @property int $id
 * @property int $system_groups_id 团活动id
 * @property int $course_id 课程id
 * @property float $group_price 课程拼团价
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemGroupXCourse newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemGroupXCourse newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\SystemGroupXCourse onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemGroupXCourse query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemGroupXCourse whereCourseId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemGroupXCourse whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemGroupXCourse whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemGroupXCourse whereGroupPrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemGroupXCourse whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemGroupXCourse whereSystemGroupsId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemGroupXCourse whereUpdatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\SystemGroupXCourse withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\SystemGroupXCourse withoutTrashed()
 * @mixin \Eloquent
 */
class SystemGroupXCourse extends Model
{
    use SoftDeletes;

    public static function getGroupCourse($group_id){
        if (!$group_id)
            return [];
        $data=self::whereSystemGroupsId($group_id)->get();
        if (count($data) > 0){
            foreach ($data as $item){
                $item->course_info=Course::getCourseInfo($item->course_id);
            }
        }
        return $data;
    }

    public static function getCourseGroup($course_id){
        if (!$course_id)
            return [];
        $result = [];
        $data=self::whereCourseId($course_id)->orderByDesc('id')->first();
        if ($data){
            $system_group_info = SystemGroup::whereId($data->system_groups_id)->first();
            if( $system_group_info )
                array_push($result,$system_group_info);
        }
        return $result;
    }
    public static function getGroupCoursePrice($SGID,$course_id){
        $data=self::whereSystemGroupsId($SGID)->whereCourseId($course_id)->first();
        $temp=Course::getCourseInfo($course_id);
        $result = [
            'group_price'=> $data ? $data->group_price : '--',
            'origion_price'=>$temp ? $temp->price : '--'
        ];
        return $result;
    }
}
